// pages/creaturedetail/creaturedetail.js
var creaturesdata = require('../../data/creatures_data.js');  

Page({

  /**
   * 页面的初始数据
   */
  data: {
    creatureUrl: "http://p06iwel4h.bkt.clouddn.com/dontstarve/creatures/",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var Name = options.Name;
    var clazz = options.clazz;
    console.log(Name);
    var items = this.getCreatures(clazz);
    console.log(items);
    var item;
    for (var i = 0; i < items.length; i++) {
      if (items[i].Name == Name) {
        item = items[i];
        break;
      }
    }
    this.setData({ item: item });
  },

  getCreatures: function (type) {
    console.log("getCreatures:" + type);
    var creatures;
    if (type == 'Land') {
      creatures = creaturesdata.creatures.Land.Creature;
    } else if (type == 'Fly') {
      creatures = creaturesdata.creatures.Fly.Creature;
    } else if (type == 'Cave') {
      creatures = creaturesdata.creatures.Cave.Creature;
    } else if (type == 'Evil') {
      creatures = creaturesdata.creatures.Evil.Creature;
    } else if (type == 'Boss') {
      creatures = creaturesdata.creatures.Boss.Creature;
    } else if (type == 'Others') {
      creatures = creaturesdata.creatures.Others.Creature;
    }
    return creatures;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})